********************************************************************************************************************************************
*************************************************** Analyze NUTS3 level data ***************************************************************
********************************************************************************************************************************************
		use "NUTS3level.dta", replace
		
		
		
********************************************************************************
****************************************** Map *********************************
********************************************************************************
				* shapefiles are from https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts 
				/*		
				* import and export database file
					import dbase using "Excel\NUTS_RG_01M_2006_4326_LEVL_3.dbf", clear
					export dbase using "Excel\NUTS_RG_01M_2006_4326_LEVL_3.dbf", replace

				* use the user written ado shp2dta to convert the files for use with stata			
					shp2dta using "Excel\NUTS_RG_01M_2006_4326_LEVL_3", database(nuts3geo_data) coordinates(nuts3geo_coord) replace
				*/
				* open saved datafile
					use "nuts3geo_data.dta", clear 

				* drop if not UK (shapefile is for Europe)
					drop if CNTR_CODE!="UK"

				* rename the NUTS 3 identifier
					rename NUTS_ID nuts3_2006
				
				* merge with import shock data
					merge 1:m nuts3_2006 using "NUTS3level.dta"

				* graph China shock d=9 for year==2008 
					drop if year!=2008 

				* growth rate measure
					spmap real_gr_imp_CH_d9 using nuts3geo_coord, id(_ID) fcolor(Heat) clmethod(custom) clbreaks(0 10 20 30 40 50 60 70 80 90 100 125 150 200 300 400) title(Growth rate) name(gr1, replace) nodraw
				
				* ADH
					spmap real_ADH_imp_CH_d9 using nuts3geo_coord, id(_ID) fcolor(Heat) clmethod(custom) clbreaks(0 200 300 400 500 600 700 800 900 1000 1250 1500 2000 2200) title(Increase per worker) name(gr2, replace) nodraw

					graph combine gr2 gr1, imargin(vsmall) name(Maps_importshocks, replace)	
					
					
********************************************************************************
************************** Summary graphs and  statistics **********************
********************************************************************************					
		use "NUTS3level.dta", replace

********************************************************************************
********************************* Scatterplots *********************************
********************************************************************************
		pwcorr real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2002
		pwcorr real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2005
		pwcorr real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2008
	
	* standard growth rate measure vs. ADH for different years
	twoway (scatter real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2002, ///
			msymbol(Oh) mlabsize(tiny) xtitle(increase per worker) ///
			xlabel(0 (200) 1000) ytitle(growth rate)) ///
			(lfit real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2002, lcolor(black)), ///
			note(r=0.53) ///
			legend(off) title(2002) name(raw2002, replace) nodraw
	twoway (scatter real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2005, ///
			msymbol(Oh) mlabsize(tiny) xtitle(increase per worker) ///
			xlabel(0 (200) 1000) ytitle(growth rate)) ///
			(lfit real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2005, lcolor(black)), ///
			note(r=0.28) ///
			legend(off) title(2005) name(raw2005, replace) nodraw
	twoway (scatter real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2008, ///
			msymbol(Oh) mlabsize(tiny) xtitle(increase per worker) ///
			xlabel(0 (200) 1000) ytitle(growth rate)) ///
			(lfit real_gr_imp_CH_d3 real_ADH_imp_CH_d3 if year==2008, lcolor(black)), ///
			note(r=0.69) ///
			legend(off) title(2008) name(raw2008, replace) nodraw
			
	graph combine raw2002 raw2005 raw2008, row(1) xcommon ycommon title(Raw measures) name(scattersraw, replace) nodraw		
			
		pwcorr real_gr_imp_CH_d3_nl_st real_ADH_imp_CH_d3_nl_st if year==2002
		pwcorr real_gr_imp_CH_d3_nl_st real_ADH_imp_CH_d3_nl_st if year==2005
		pwcorr real_gr_imp_CH_d3_nl_st real_ADH_imp_CH_d3_nl_st if year==2008

			
	twoway (scatter real_gr_imp_CH_d3_nl real_ADH_imp_CH_d3_nl if year==2002, ///
			msymbol(Oh) mlabsize(tiny) xtitle(increase per worker) ytitle(growth rate)) ///
			(lfit real_gr_imp_CH_d3_nl real_ADH_imp_CH_d3_nl if year==2002, lcolor(black)), ///
			note(r=0.65) ///
			legend(off) title(2002) name(log2002, replace) nodraw
	twoway (scatter real_gr_imp_CH_d3_nl real_ADH_imp_CH_d3_nl if year==2005, ///
			msymbol(Oh) mlabsize(tiny) xtitle(increase per worker) ytitle(growth rate)) ///
			(lfit real_gr_imp_CH_d3_nl real_ADH_imp_CH_d3_nl if year==2005, lcolor(black)), ///
			note(r=0.59) ///
			legend(off) title(2005) name(log2005, replace) nodraw	
	twoway (scatter real_gr_imp_CH_d3_nl real_ADH_imp_CH_d3_nl if year==2008, ///
			msymbol(Oh) mlabsize(tiny) xtitle(increase per worker) ytitle(growth rate)) ///
			(lfit real_gr_imp_CH_d3_nl real_ADH_imp_CH_d3_nl if year==2008, lcolor(black)), ///
			note(r=0.77) ///
			legend(off) title(2008) name(log2008, replace) nodraw
			
	graph combine log2002 log2005 log2008, row(1) xcommon ycommon title(Logged measures) name(scatterslogged, replace) nodraw
	
	graph combine scattersraw scatterslogged, col(1) imargin(zero) iscale(*1.3) name(scatterscombined_importshock, replace)